#include "public.h"

void public()
{
    printf("up");
}



void Upd_file_all(void *data, char *path, size_t m, size_t n)
{
    FILE *fp = fopen(path, "r+");

    fseek(fp, m, SEEK_SET);
    fwrite(data, n, 1, fp);

    fclose(fp);
}

char *int2str(long long num)
{
    static char value[21] = "";
    short symbol = 0, len = 0, i = 0;
    long long temp_num = 0;

    if (num < 0)
    {
        symbol = 1; // 空间换时间
        num = num * -1;
        value[0] = '-';
    }

    temp_num = num;

    while (temp_num /= 10)
    {
        len++;
    }

    for (i = 20; i >= 0; i--)
    {

        if (len >= i)
        {

            value[i + symbol] = num % 10 + '0';
            num /= 10;
        }
    }

    return value;
}

void strcat_us(char *dast, const char *str)
{
    int i = 0;
    while (*dast != '\0')
    {
        dast++;
    }

    while (*(str + i) != '\0')
    {
        *(dast + i) = *(str + i);
        i++;
    }
}
int cmp_file(FILE *file_dast, FILE *file_str, size_t len) // 缓冲区空间
{
    feof(file_str);
    feof(file_dast);
    long int location_a = ftell(file_dast);
    long int location_b = ftell(file_str);
    if (location_a != location_b)
    {
        return 1;
    }
    rewind(file_dast);
    rewind(file_str);

    char *temp_dast = (char *)calloc(1, len);
    char *temp_str = (char *)calloc(1, len);
    if (NULL == temp_dast || NULL == temp_str)
    {
        fprintf(stderr, "cmp_file:: Failed to allocate memory space！\n");
        exit(1);
    }

    while (fread(temp_dast, 1, len, file_dast) && fread(temp_str, 1, len, file_str))
    {
        if (memcmp(temp_dast, temp_str, len) != 0)
        {
            return 1;
        }
    }

    return 0; // 相同返回 0   不同返回 1
}

int input_check()
{
    const char *pattern = "^[A-Za-z0-9[:punct:]]*$";

    // regex_t regex;
    int ret;
}
